package com.xmler.plugin.adbrocket.adb.command

import com.android.ddmlib.IDevice
import com.intellij.openapi.project.Project
import com.xmler.plugin.adbrocket.adb.command.receiver.DisplayReceiver
import org.jetbrains.android.facet.AndroidFacet
import java.util.concurrent.TimeUnit
import javax.swing.JTextArea

class KeyboardInputCmd(private val text: String) : ICommand{

    override fun run(
        project: Project,
        device: IDevice,
        facet: AndroidFacet,
        packageName: String,
        display: JTextArea
    ): Boolean {
        try {
            val cmd = StringBuilder("input keyboard text '")
                .append(text)
                .append("'")

            device.executeShellCommand(cmd.toString(), WrapperReceiver(DisplayReceiver(display), display), 10L, TimeUnit.SECONDS)
            return true
        } catch (e: Exception) {

        }
        return false
    }
}
